package common.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * description:
 *
 * @author yanxf@winning.com.cn
 * @date 2020/04/07 18:31
 */
@Component
public class JdbcTemplateRepository {


    @Autowired
    private JdbcTemplate ptStoreJdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
        return ptStoreJdbcTemplate;
    }

    private TransactionTemplate transactionTemplate;

    @Resource
    public void setDataSource(DataSource dataSource) {
        ptStoreJdbcTemplate = new JdbcTemplate(dataSource);
    }

    @Resource
    public void setDefaultTransactionManager(PlatformTransactionManager defaultTransactionManager) {
        transactionTemplate = new TransactionTemplate(defaultTransactionManager);
    }

    public TransactionTemplate getTransactionTemplate() {
        return transactionTemplate;
    }

    public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
        this.transactionTemplate = transactionTemplate;
    }

}
